package com.ttg.web.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttg.common.entities.BasePage;
import com.ttg.common.enums.AdminStatusEnum;
import com.ttg.model.mapper.AdminMapper;
import com.ttg.model.pojo.Admin;
import com.ttg.model.vo.AdminIndexVO;
import com.ttg.web.dao.AdminDao;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ZQ
 * @version 1.0
 * @Description
 * @date 2021/1/26 13:26
 */
@Service
public class AdminDaoImpl extends ServiceImpl<AdminMapper, Admin> implements AdminDao {


    @Override
    public boolean saveOrUpdatePwd(Admin admin) {
        return saveOrUpdate(admin);
    }

    @Override
    public Integer countByUserName(String admUserName) {
        LambdaQueryWrapper<Admin> wrapper = Wrappers.lambdaQuery();
        wrapper.ne(Admin::getAdmStatus, AdminStatusEnum.TYPE_4.getValue())
                .eq(Admin::getAdmUserName, admUserName);
        return count(wrapper);
    }

    @Override
    public Admin saveAdm(Admin admin) {
        int insert = baseMapper.insert(admin);
        return admin;
    }

    @Override
    public Admin findAdmByUserName(String userName) {
        LambdaQueryWrapper<Admin> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Admin::getAdmUserName, userName);
        return getOne(wrapper);
    }



    @Override
    public BasePage<AdminIndexVO> adminIndexGetPage(BasePage page,Integer status, String admId,String trueName,String userName) {
        return baseMapper.adminIndexGetPage(page, status,admId, trueName,userName);
    }

    @Override
    public int countByAdmRoleId(Long admRoleId) {
        LambdaQueryWrapper<Admin> wrapper = Wrappers.lambdaQuery();
        wrapper.ne(Admin::getAdmStatus, AdminStatusEnum.TYPE_4.getValue())
                .apply("FIND_IN_SET({0},adm_role_id)", admRoleId);
        return count(wrapper);
    }
	
	@Override
    public List<Admin> getAdmins(List<Long> admId, Integer admWarn) {
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Admin::getAdmId,Admin::getAdmTrueName,Admin::getAdmMobile)
                .eq(Admin::getAdmWarn,admWarn)
                .in(Admin::getAdmId,admId);
        return baseMapper.selectList(wrapper);
    }
}
